package com.cash.channel.api.model.channel;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

//@Data
@ToString
public class ChannelModel implements Serializable {

    @JsonProperty("nId")
    private Integer nId;

    @JsonProperty("cChannel")
    private String cChannel;

    @JsonProperty("cChannelName")
    private String cChannelName;

    @JsonProperty(value = "nCustom", defaultValue = "0")
    private Integer nCustom;

    @JsonProperty("cChannelPublicKey")
    private String cChannelPublicKey;

    @JsonProperty("cChannelPrivateKey")
    private String cChannelPrivateKey;

    @JsonProperty("cPlatformPublicKey")
    private String cPlatformPublicKey;

    @JsonProperty("cPlatformPrivateKey")
    private String cPlatformPrivateKey;

    @JsonProperty("cChannelAesKey")
    private String cChannelAesKey;

    @JsonProperty("cPlatformAesKey")
    private String cPlatformAesKey;

    @JsonProperty(value = "nOperatorStatus", defaultValue = "0")
    private Integer nOperatorStatus;

    @JsonProperty("cProductCode")
    private String cProductCode;

    @JsonProperty(value = "nInUse", defaultValue = "1")
    private Integer nInUse;

    @JsonProperty("operator")
    private String operator;

    @JsonProperty("operatorName")
    private String operatorName;

    @JsonProperty("dailyLimit")
    private String dailyLimit;

   /* @JsonProperty("creditPlatformName")
    private String creditPlatformName;

    @JsonProperty("creditPlatformDailyLimit")
    private String creditPlatformDailyLimit;

    @JsonProperty("creditPlatformStatus")
    private Integer creditPlatformStatus;*/

    @JsonProperty("cCredentialConfig")
    private String cCredentialConfig;

    @JsonProperty("credentialConfigObject")
    private Map<String, Boolean> credentialConfigObject;

    @JsonProperty("cRequireParams")
    private String cRequireParams;

    @JsonProperty("requireParamsMap")
    private Map<String, Boolean> requireParamsMap;

    @JsonProperty("cChannelId")
    private String cChannelId;

    public String getcChannelId() {
        return cChannelId;
    }

    public void setcChannelId(String cChannelId) {
        this.cChannelId = cChannelId;
    }

    private String[] credentialConfigParams = new String[]{};

    private String[] requireParamsConfigParams = new String[]{};

    public ChannelModel() {
    }

    public ChannelModel(String[] credentialConfigParams, String[] requireParamsConfigParams) {
        this.credentialConfigParams = credentialConfigParams;
        this.requireParamsConfigParams = requireParamsConfigParams;
    }

    public Map<String, Boolean> getCredentialConfigObject() {
        if (this.credentialConfigObject==null || this.credentialConfigObject.isEmpty()) {
            if (StringUtils.isEmpty(this.cCredentialConfig)) {
                return initCredentialConfigMap();
            } else {
                return JSON.parseObject(this.cCredentialConfig, Map.class);
            }
        }
        return this.credentialConfigObject;
    }

    private Map<String, Boolean> initCredentialConfigMap() {
        Map<String, Boolean> resultMap = Maps.newHashMap();
        Arrays.stream(this.credentialConfigParams).forEach(p->resultMap.put(p, false));
        return resultMap;
    }

    private Map<String, Boolean> initRequireParamsMap() {
        Map<String, Boolean> resultMap = Maps.newHashMap();
        Arrays.stream(this.requireParamsConfigParams).forEach(p->resultMap.put(p, false));
        return resultMap;
    }

    public void setCredentialConfigParams(String... params) {
        this.credentialConfigParams = params;
    }

    public void setRequireParamsConfigParams(String... params) {
        this.requireParamsConfigParams = params;
    }

    public void setCredentialConfigObject(String credentialConfigObject) {
        this.cCredentialConfig = credentialConfigObject;
    }

    public Map<String, Boolean> getRequireParamsMap() {
        if (this.requireParamsMap==null || this.requireParamsMap.isEmpty()) {
            if (StringUtils.isEmpty(this.cRequireParams)) {
                return initRequireParamsMap();
            } else {
                return JSON.parseObject(this.cRequireParams, Map.class);
            }
        }
        return this.requireParamsMap;
    }

    public void setRequireParamsMap(String requireParamsMap) {
        this.cRequireParams = requireParamsMap;
    }

    public Integer getnId() {
        return nId;
    }

    public void setnId(Integer nId) {
        this.nId = nId;
    }

    public String getcChannel() {
        return cChannel;
    }

    public void setcChannel(String cChannel) {
        this.cChannel = cChannel;
    }

    public String getcChannelName() {
        return cChannelName;
    }

    public void setcChannelName(String cChannelName) {
        this.cChannelName = cChannelName;
    }

    public Integer getnCustom() {
        return nCustom;
    }

    public void setnCustom(Integer nCustom) {
        this.nCustom = nCustom;
    }

    public String getcChannelPublicKey() {
        return cChannelPublicKey;
    }

    public void setcChannelPublicKey(String cChannelPublicKey) {
        this.cChannelPublicKey = cChannelPublicKey;
    }

    public String getcChannelPrivateKey() {
        return cChannelPrivateKey;
    }

    public void setcChannelPrivateKey(String cChannelPrivateKey) {
        this.cChannelPrivateKey = cChannelPrivateKey;
    }

    public String getcPlatformPublicKey() {
        return cPlatformPublicKey;
    }

    public void setcPlatformPublicKey(String cPlatformPublicKey) {
        this.cPlatformPublicKey = cPlatformPublicKey;
    }

    public String getcPlatformPrivateKey() {
        return cPlatformPrivateKey;
    }

    public void setcPlatformPrivateKey(String cPlatformPrivateKey) {
        this.cPlatformPrivateKey = cPlatformPrivateKey;
    }

    public String getcChannelAesKey() {
        return cChannelAesKey;
    }

    public void setcChannelAesKey(String cChannelAesKey) {
        this.cChannelAesKey = cChannelAesKey;
    }

    public String getcPlatformAesKey() {
        return cPlatformAesKey;
    }

    public void setcPlatformAesKey(String cPlatformAesKey) {
        this.cPlatformAesKey = cPlatformAesKey;
    }

    public Integer getnOperatorStatus() {
        return nOperatorStatus;
    }

    public void setnOperatorStatus(Integer nOperatorStatus) {
        this.nOperatorStatus = nOperatorStatus;
    }

    public String getcProductCode() {
        return cProductCode;
    }

    public void setcProductCode(String cProductCode) {
        this.cProductCode = cProductCode;
    }

    public Integer getnInUse() {
        return nInUse;
    }

    public void setnInUse(Integer nInUse) {
        this.nInUse = nInUse;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

   /* public String getCreditPlatformName() {
        return creditPlatformName;
    }

    public void setCreditPlatformName(String creditPlatformName) {
        this.creditPlatformName = creditPlatformName;
    }
*/
    public String getcCredentialConfig() {
        return cCredentialConfig;
    }

    public void setcCredentialConfig(String cCredentialConfig) {
        if (StringUtils.isEmpty(this.cCredentialConfig)) {
            this.cCredentialConfig = JSON.toJSONString(this.credentialConfigObject);
        }
        this.cCredentialConfig = cCredentialConfig;
    }

    public String getcRequireParams() {
        return cRequireParams;
    }

    public void setcRequireParams(String cRequireParams) {
        if (StringUtils.isEmpty(this.cRequireParams)) {
            this.cRequireParams = JSON.toJSONString(this.requireParamsMap);
        }
        this.cRequireParams = cRequireParams;
    }

    public String getDailyLimit() {
        return dailyLimit;
    }

    public void setDailyLimit(String dailyLimit) {
        this.dailyLimit = dailyLimit;
    }

   /* public String getCreditPlatformDailyLimit() {
        return creditPlatformDailyLimit;
    }

    public void setCreditPlatformDailyLimit(String creditPlatformDailyLimit) {
        this.creditPlatformDailyLimit = creditPlatformDailyLimit;
    }

    public Integer getCreditPlatformStatus() {
        return creditPlatformStatus;
    }

    public void setCreditPlatformStatus(Integer creditPlatformStatus) {
        this.creditPlatformStatus = creditPlatformStatus;
    }*/
}
